package com.ghpt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ghpt.mapper.ShiChangMapper;
import com.ghpt.pojo.ShiChang;
import com.ghpt.service.ShiChangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ShiChangServiceImpl implements ShiChangService {
    @Autowired
    private ShiChangMapper shiChangMapper;

    @Override
    public ShiChang findShiChangById(Long id) {
        if (id != null) {
            return shiChangMapper.selectById(id);
        }else {
            return null;
        }
    }
    @Override
    public int updateById(ShiChang shiChang) {
        return shiChangMapper.updateById(shiChang);//更新成功为1否则为0
    }
    @Override
    public int updateValue(Long id, Double value) {
        UpdateWrapper<ShiChang> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id).set("value", value);
        return shiChangMapper.update(null, updateWrapper);
    }

    @Override
    public void replaceRows(List<ShiChang> data) {

    }

    @Override
    public List<String> getTableColumns() {
        return Arrays.asList("id", "value");
    }



    @Override
    public void replaceRows(Long startId, Long endId, List<ShiChang> data) {
        QueryWrapper<ShiChang> wrapper = new QueryWrapper<>();
        wrapper.between("id", startId, endId);
        shiChangMapper.delete(wrapper);

        for (ShiChang e : data) {
            shiChangMapper.insert(e);
        }
    }
}
